package com.tsu.mall.order.Controller;

import com.tsu.mall.common.VO.BillWaresVO;
import com.tsu.mall.common.entity.Bill;
import com.tsu.mall.common.entity.BillAddress;
import com.tsu.mall.common.entity.Member;
import com.tsu.mall.common.entity.Wares;
import com.tsu.mall.common.service.IBillAddressService;
import com.tsu.mall.common.service.IBillService;
import com.tsu.mall.common.service.IMemberService;
import com.tsu.mall.common.service.IWaresService;
import com.tsu.mall.common.util.RequestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/billDetail")
public class BillDetailController {
    @Autowired
    private IMemberService iMemberService;
    @Autowired
    private IWaresService iWaresService;
    @Autowired
    private IBillAddressService iBillAddressService;
    @Autowired
    private IBillService iBillService;
    @GetMapping("/billDetailPage")
    public String billDetailPage(Model model,Integer billId){
        //查询当前订单的信息
        Bill bill=iBillService.selectById(billId);
        model.addAttribute("bill",bill);
        //查询当前订单的收货地址信息
        BillAddress billAddress=iBillAddressService.selectBillAddressByBillId(billId);
        model.addAttribute("billAddress",billAddress);
        //查询当前订单的所有商品信息
        List<BillWaresVO> wares=iWaresService.selectWaresByBillId(billId);
        model.addAttribute("billWares",wares);
        //查询当前登录用户信息
        Member currentMember=iMemberService.doSelectById(RequestUtil.getCurrent().getId());
        model.addAttribute("currentMember",currentMember);
        return "billDetail";
    }
}
